package com.siae;


import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;

@SpringBootApplication
@MapperScan("com.siae.mapper")
public class SiaeApp {

    public static void main(String[] args) {
        SpringApplication.run(SiaeApp.class,args);
    }
    /**
     * 解决跨域的过滤器bean对象
     * @Bean 注解表示当前类中的方法返回的对象需要交给Spring管理
     * */
    @Bean
    public CorsFilter corsFilter(){
        CorsConfiguration corsConfiguration = new CorsConfiguration();
        // 允许哪些域名访问
        corsConfiguration.addAllowedOrigin("*");
        // 允许哪些请求方式
        corsConfiguration.addAllowedMethod("*");
        // 允许哪些请求头
        corsConfiguration.addAllowedHeader("*");
        UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
        source.registerCorsConfiguration("/**",corsConfiguration);
        return new CorsFilter(source);
    }
}
